package com.blkkj.huan.Controller;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.iot.model.v20170420.BatchGetDeviceStateRequest;
import com.aliyuncs.iot.model.v20170420.BatchGetDeviceStateResponse;
import com.blkkj.huan.Modle.JSONResult;
import com.blkkj.huan.util.BaseTest;
import com.blkkj.huan.util.LogUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class batchGetDeviceStatusController extends BaseTest {


    @PostMapping("/BatchGetDeviceState")
    public String batchGetDeviceStatus( String productKey, @RequestParam("deviceNames") List<String> deviceNames){

        batchGetDeviceStatusTest(productKey, deviceNames);
        BatchGetDeviceStateRequest request = new BatchGetDeviceStateRequest();
        BatchGetDeviceStateResponse response = (BatchGetDeviceStateResponse)executeTest(request);
        return JSONResult.fillResultString(0, "", response);

    }



    /**
     * 批量查询设备状态
     *
     * @param productKey 产品pk
     * @param deviceNames 设备名称集合
     */
    public static void batchGetDeviceStatusTest(String productKey,  List<String> deviceNames) {
        BatchGetDeviceStateRequest request = new BatchGetDeviceStateRequest();
        request.setProductKey(productKey);
        request.setDeviceNames(deviceNames);
        BatchGetDeviceStateResponse response = (BatchGetDeviceStateResponse)executeTest(request);
        if (response != null && response.getSuccess() != false) {
            LogUtil.print("查询设备成功！ " + JSONObject.toJSONString(response));
        } else {
            LogUtil.error("查询设备失败！requestId:" + response.getRequestId() + "原因：" + response.getErrorMessage());
        }
    }
}
